#include "Core/Log/LogManager.h"
#include "Core/Network/Socket.h"
#include "Core/Profile/CodeProfile.h"
#include "SocketTest.h"

const char * SocketTest::GetName() const
{
	return "Socket Test";
}

error SocketTest::Create()
{
	if(Failed(UnitTest::Create()))
		return errFailed;

	m_server = new Server();
	m_server->Start();

	sleep(1);

	return errOK;
}

error SocketTest::Destroy()
{
	if(Failed(UnitTest::Destroy()))
		return errFailed;

	ThreadLauncher launcher;
	launcher.WaitFor(m_server);

	delete m_server;

	return errOK;
}

error SocketTest::Execute()
{
	PROFILE(GetName());

	TCPSocket s;
	s.Connect("127.0.0.1", port);

	// wait a little bit
	sleep(1);

	int i=255;
	s.Send(&i, sizeof(i));

	return errOK;
}
